const mongoose = require("mongoose");
var Food = mongoose.model("food");

exports.findAllFood = function(req, res) {
    Food.find(function(err, foods) {
        res.json(foods);
    });
}

exports.passStatus = function(req, res) {
    Food.findOne({ fId: req.params.id }, function(err, food) {

        food.fStatus = 3;
        food.save(function(err) {
            if (!err) {
                res.send("success");
            } else {
                res.json({ error: "passStatus" });
            }
        })

    })

}
exports.refuseStatus = function(req, res) {
    Food.findOne({ fId: req.params.id }, function(err, food) {

        food.fStatus = 2;
        food.save(function(err) {
            if (!err) {
                res.send("success");
            } else {
                res.json({ error: "refuseStatus" });
            }
        })

    })

}
exports.showPassFIdWS=function(req,res){//odd protocol
    Food.find({fStatus:2},function(err,foods){
        // var passFId=[];
        var passFId="";
        foods.forEach(function(item){
            // passFId.push(item.fId);
            passFId=passFId+item.fId+",";
        })
        res.send(passFId);
    })
}
